import dom, { ajax } from "../init.js";
import { obj } from "../index.js";

const arr = [
  { title: "dfdfffddfdffdf" },
  { title: "dfdfffddfdffdf" },
  { title: "dfdfffddfdffdf" },
  { title: "dfdfffddfdffdf" },
  { title: "dfdfffddfdffdf" },
  { title: "dfdfffddfdffdf" },
  { title: "dfdfffddfdffdf" },
];
const arr1 = [
  { title: "ghg4r54454455" },
  { title: "ghg4r54454455" },
  { title: "ghg4r54454455" },
  { title: "ghg4r54454455" },
  { title: "ghg4r54454455" },
  { title: "ghg4r54454455" },
  { title: "ghg4r54454455" },
];
const arr2 = [
  { title: "23dsafdsfwehu4" },
  { title: "23dsafdsfwehu4" },
  { title: "23dsafdsfwehu4" },
  { title: "23dsafdsfwehu4" },
  { title: "23dsafdsfwehu4" },
  { title: "23dsafdsfwehu4" },
  { title: "23dsafdsfwehu4" },
];

export async function topover() {
  if (event.target === dom.top.gift) {
    animate(dom.top.position, event.target.offsetLeft);
  } else if (event.target === dom.top.heat) {
    animate(dom.top.position, event.target.offsetLeft);
  } else if (event.target === dom.top.time) {
    animate(dom.top.position, event.target.offsetLeft);
  }
}

export async function topout() {
  animate(dom.top.position, obj.top);
}

export async function topclick() {
  if (event.target === dom.top.gift) {
    obj.top = event.target.offsetLeft;
    updateTop(arr, "icon-liwuhuodong");
  } else if (event.target === dom.top.heat) {
    obj.top = event.target.offsetLeft;
    updateTop(arr1, "icon-redu");
  } else if (event.target === dom.top.time) {
    obj.top = event.target.offsetLeft;
    updateTop(arr2, "icon-shijian_o");
  }
}
//渲染top
function updateTop(arr = [], icon) {
  dom.top.topes1.innerHTML = "";
  arr.forEach((item, index) => {
    let str = `        <div class="atk">
    <span>${index + 1}.</span>
    <a href=""> ${item.title}</a>
    <span class="iconfont ${icon} t${index + 1}"></span>
    </div>`;
    dom.top.topes1.insertAdjacentHTML("beforeend", str);
  });
}
